#include "JointControlDialog.hpp"

#include <QtGui>


PosTab::PosTab(JointController* jcontroller, rw::kinematics::State* state,QWidget *parent)
       : QWidget(parent),_state(state),_jcont(jcontroller)
{
   if( !(jcontroller->getControlModes() & JointController::POSITION) )
       this->setDisabled(true);

   int row = 0;

   QGridLayout* lay = new QGridLayout(this);
   this->setLayout(lay);

   _jogGroup = new JogGroup(jcontroller->getModel());
   lay->addWidget(_jogGroup,row++,0);
   connect(_jogGroup, SIGNAL(updateSignal()), this, SLOT(targetChanged()));

   {
       QPushButton *button = new QPushButton(tr("Set target"));
       lay->addWidget(button,row++,0);
       connect(button, SIGNAL(clicked()), this, SLOT(setTarget()));

   }
   {
       QPushButton *button = new QPushButton(tr("Get q state"));
       lay->addWidget(button,row++,0);
       connect(button, SIGNAL(clicked()), this, SLOT(getQState()));

   }

}

void PosTab::setTarget(){
    rw::math::Q target = _jogGroup->getQ();
    _jcont->setTargetPos( target );
}

void PosTab::targetChanged(){
    std::cout << "Target Changed: " << _jogGroup->getQ() << std::endl;
}

SimulatorDialog::SimulatorDialog(JointController* jcontroller, rw::kinematics::State* state, QWidget *parent)
    : QDialog(parent),_state(state)
{
    tabWidget = new QTabWidget;
    tabWidget->addTab(new SyncTab(jcontroller), tr("Sync"));
    tabWidget->addTab(new PosTab(jcontroller, _state), tr("Pos"));
    tabWidget->addTab(new VelTab(jcontroller), tr("Vel"));
    tabWidget->addTab(new CurTab(jcontroller), tr("Cur"));

    QPushButton *okButton = new QPushButton(tr("OK"));
    QPushButton *cancelButton = new QPushButton(tr("Cancel"));

    connect(okButton, SIGNAL(clicked()), this, SLOT(accept()));
    connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));

    QHBoxLayout *buttonLayout = new QHBoxLayout;
    buttonLayout->addStretch(1);
    buttonLayout->addWidget(okButton);
    buttonLayout->addWidget(cancelButton);

    QVBoxLayout *mainLayout = new QVBoxLayout;
    mainLayout->addWidget(tabWidget);
    mainLayout->addLayout(buttonLayout);
    setLayout(mainLayout);

    setWindowTitle(tr("Tab Dialog"));
}

